package com.qiezikaka.kaka.net.api;


import static com.qiezikaka.kaka.net.http.HttpUrl.DEFAULT_TIMEOUT;


import com.qiezikaka.kaka.net.http.HttpUrl;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;


/**
 * @user zhangjinbo
 * @Description Retrofit初始化
 */
public class ControlClient {

    private final ApiService mAppApi;

    public ControlClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .client(OkHttpManager.getInstance())
                //.addConverterFactory(new NullOnEmptyConverterFactory())
                .addConverterFactory(CustomGsonConverterFactory.create())   //  //GsonConverterFactory.create()
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(HttpUrl.API_PATH)
                .build();


        mAppApi = retrofit.create(ApiService.class);
    }

    /**
     * 获取api的管理类
     * @return
     */
    public ApiService getControlApi() {
        return mAppApi;
    }

}
